package jp.peach_boys.sandbox.slim3.controller;

import jp.peach_boys.sandbox.slim3.entity.Image;
import jp.peach_boys.sandbox.slim3.entity.Memo;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.upload.FileItem;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

public class MemoController extends Controller {

    @Override
    protected Navigation run() throws Exception {
        Memo memo = new Memo();
        BeanUtil.copy(request, memo);
        Datastore.put(memo);
        
        ///////////////////////add@3rd
        Image image = new Image();
        FileItem file;
        if((file = requestScope("image")) != null){
            image.setRcd((String) requestScope("rcd"));
            image.setFilename(file.getFileName());
            image.setImage(file.getData());
            Datastore.put(image);
        }
        //////////////////////////////
        
        return redirect("/");
    }

}
